﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _002
{
/// <summary>
/// 静态构造函数不能有访问修饰符，它会在使用带参数构造函数进行初始化时被自动调用或访问静态数据成员时调用。
/// </summary>

    internal class Program
    {
        static void Main(string[] args)
        {
            //实例化时自动调用静态函数
            Student s3 = new Student("C#", 3);
            //访问静态成员时会自动调用
            Console.WriteLine(Student.id);
            //给静态成员赋值时自动调用
            Student.id = 1;
            Console.WriteLine(Student.id);
            Console.ReadKey();
        }
        struct Student
        {
            public string name;
            public int age;
            public static int id;
            public Student(string name,int age)
            {
                this.name = name;
                this.age = age;
            }
            static Student()
            {
                Console.WriteLine("静态构造函数被自动调用了。。");
            }
        }
    }
    
}
